package view;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import model.Oneshape;
import model.Wall;

public class GamePanel extends JPanel implements Observer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1860979716621182121L;
	private Oneshape oneshape;
	private Wall wall;
	public static final int WIDTH = 20;
	public static final int HEIGHT = 20;

	public GamePanel() {
		setSize(400, 550);
		setLocation(0, 0);
		setBackground(Color.ORANGE);
		setBorder(BorderFactory.createRaisedSoftBevelBorder());
	}
	
	public GamePanel(Wall wall) {
		this();
		this.wall = wall;
	}

	@Override
	public void paint(Graphics g) {
		Color color = oneshape.getColor();
		super.paint(g);
		if (oneshape == null)
			return;
		int[][] cshape = oneshape.getShape();
		int x = oneshape.getX(), y = oneshape.getY();
		for (int i = 0; i < cshape.length; i++) {
			for (int j = 0; j < cshape[i].length; j++) {
				if (cshape[i][j] == 1) {
					g.setColor(color);
					g.fill3DRect(x + i * WIDTH, y + j * HEIGHT, WIDTH, HEIGHT, true);
				}
			}
			
		}
		int[][] wallspace=wall.getWall();
		for(int wi=0;wi<wallspace.length;wi++)
		{
			for(int wj=0;wj<wallspace[wi].length;wj++)
			{
				if(wallspace[wi][wj]==1)
				{
					
					g.setColor(new Color(0x90EE90));
					g.fill3DRect(wi*WIDTH, wj*HEIGHT, WIDTH, HEIGHT, true);
				}
			}
		}
	}

	@Override
	public void update(Observable o, Object arg) {
		Oneshape os = (Oneshape) arg;
		if (os.isNext())
			return;
		this.oneshape = (Oneshape) arg;
		repaint();
	}
}
